using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BGMLoop_Ctrl : MonoBehaviour
{
    public AudioSource audioSource;
    public float loopBackInitPointTime;
    public float loopBackTargetPointTime;
    public float pitch = 1;
    [Range(0,1)]
    public float loopRange;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (audioSource != null && audioSource.isPlaying )
        {
            audioSource.pitch = pitch;
            loopRange = (audioSource.time - loopBackInitPointTime) / (loopBackTargetPointTime - loopBackInitPointTime);
            if (loopBackTargetPointTime >= loopBackInitPointTime && (audioSource.time >= loopBackTargetPointTime || audioSource.time >= audioSource.clip.length * audioSource.pitch))
            {
                audioSource.time = loopBackInitPointTime;
            }
        }
    }
}
